package com.zwz.utils;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

@Slf4j
public class ConvertWithPrecisionWarning {

    public static Double convertWithPrecisionWarning(BigDecimal value) {
        if (value == null) return null;

        // 记录原始值的字符串表示，用于对比精度损失
        String original = value.toPlainString();
        Double converted = value.doubleValue();
        String afterConversion = converted.toString();

        if (!original.equals(afterConversion)) {
           log.info("精度丢失: Original=" + original
                    + " → Converted=" + afterConversion);
        }
        return converted;
    }

}
